﻿<?php
	error_reporting(E_ALL^E_NOTICE);
	require_once ('./config/config.php'); 
	require_once ('./class/email.class.php'); 
	require_once ('./class/tools.class.php');
	date_default_timezone_set("PRC");
	session_start();
	if(empty($_SESSION['user'])){
		echo "<script>location='./login.php';</script>";
		exit();
	}else{
		$userRs=mysqli_fetch_array(mysqli_query($con,"select * from user where user='".$_SESSION['user']."'"));
		if($_GET['oper']=="logout"){
			unset($_SESSION['user']);
			echo "<script>location='./index.php';</script>";
			exit();
		}
	}
?>
<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js">
<!--<![endif]-->
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>某高校图书共享网站</title>
		<meta name="description" content="A responsive web app template with common components like profile, list, tabs, menu views. Made for Codrops exclusively.">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<link rel="stylesheet" href="./assets/output.css">
		<link rel="stylesheet" href="./assets/node_modules/tippy.js/dist/themes/light.css">
		<link rel="stylesheet" href="./layui/css/layui.css">
		<script src="./layui/js/layui.js" v="layui" e="layui"></script>
	</head>
	<body class="bg-grey-lighter font-sans antialiased">
		<!--[if lt IE 7]>
			<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p>
		<![endif]-->
		<div class="bg-indigo-darker text-center p-4 px-6 flex items-center">
			<div class="hidden lg:block lg:w-1/4 xl:w-1/5 pr-8">
				<font color="#ffffff"><h1>某高校图书共享网站</h1></font>
			</div>
		</div>
		<!-- Main -->
		<div class="flex">
			<!-- Content -->
			<div class="flex flex-1 flex-col md:px-6 pt-10" id="content">
				<!-- Title -->
				<div class="px-6 md:px-0 flex justify-between items-center -order-1">
					<div>
						<h2 class="font-normal"><a href="./index.php">首页</a> / <a href="./my.php">个人中心</a> / 我的订单</h2>
					</div>
					<p>欢迎您，<?php echo $_SESSION['user'];?> !</p>
				</div>
				<!-- Desktop Stats -->
				<div class="hidden px-6 md:px-0 mt-4 md:flex flex-wrap order-1 md:-order-1 md:shadow-md js-tab-pane" id="section-stats">
					<div class="p-4 px-6 w-full md:w-1/2 rounded md:rounded-r-none bg-white shadow-md md:shadow-none">
						<table class="mt-4 w-full">
							<thead class="p-2 text-sm leading-loose border-b text-indigo">
								<tr>
									<td>订单编号</td>
									<td class="text-center">订单详情</td>
									<td class="text-center">订单金额</td>
									<td class="text-center">订单状态</td>
									<td class="text-center">关联借阅</td>
									<td class="text-right">操作</td>
								</tr>
							</thead>
							<tbody class="p-2 leading-loose text-sm">
								<?php
									$order_record=mysqli_query($con,"select * from order_record where uid='".$userRs['uid']."' order by rid asc");
									while($orRs=mysqli_fetch_array($order_record)){ 
										$bookRs=mysqli_fetch_array(mysqli_query($con,"select * from book_sharing where bid='".$orRs['bid']."'"));
										$brRs=mysqli_fetch_array(mysqli_query($con,"select * from borrowing_record where bid='".$orRs['bid']."'"));
								?>
										<tr class="border-b">
											<td class="py-2"><?php echo $orRs['order_no'];?></td>
											<td class="py-2 text-center"><?php echo $orRs['order_content'];?></td>
											<td class="py-2 text-center"><?php echo $orRs['order_price'];?>HY币</td>
											<td class="py-2 text-center">
												<?php 
													if($orRs['order_state']=="0"){
														echo "未支付";
													}elseif($orRs['order_state']=="1"){
														$refund=mysqli_fetch_array(mysqli_query($con,"SELECT * FROM `refund_record` where `order_no`='".$orRs['order_no']."'"));
														if($refund['refund_id']==""){
															echo "已支付";
														}else{
															echo "已退款";
														}
													}
												?>
											</td>
											<td class="py-2 text-center"><?php echo $bookRs['book_name'];?></td>
											<td class="py-2 text-right">
												<?php
													if($orRs['order_state']=="0"){
														if($brRs['state']=="1"){
															echo "<a href='./pay/test.php?orid=".$orRs['rid']."'>支付押金</a>";
														}elseif($brRs['state']=="0"){
															echo "等待接受";
														}else{
															echo "暂无操作";
														}
													}else{
														echo "暂无操作";
													}
												?>
											</td>
										</tr>
								<?php		
									}
								?>
							</tbody>
						</table>
					</div>
					<div class="w-full md:w-1/2 p-4 md:pt-12 md:pl-1 mt-4 md:mt-0 lg:pt-12 lg:pl-8 rounded md:rounded-r-none bg-white shadow-md md:shadow-none">
					</div>
				</div>
			</div>
		</div>
		<script src="./assets/bundle.js" async defer></script>
</body>
</html>